package com.yihuier.yihuier.Mapper.UserManager;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;

@Mapper
public interface DepartmentUserMapper {

    @Select("SELECT user_id  FROM bz_department_user WHERE department_id = #{department_id};")
    ArrayList<Integer> selectUsersByDepartmentId(@Param("department_id")int department_id);

    /**
     * 通过用户user_id找到用户部门编号
     * @param user_id 用户编号
     * @return 用户部门编号
     */
    @Select("SELECT department_id FROM `bz_department_user` WHERE user_id = #{user_id};")
    int selectDepartmentIdByUserid(@Param("user_id") int user_id);

    /**
     * 通过用户user_id找到用户部门编号
     * @param department_id 用户部门编号编号
     * @return 用户部门编号
     */
    @Select("SELECT  Count(user_id) FROM `bz_department_user` WHERE department_id = #{department_id};")
    int selectSumOfUsersInDepartment(@Param("department_id") int department_id);

    /**
     * 管理员添加新用户，再部门用户表中添加信息
     * */
    @Insert("INSERT INTO bz_department_user(department_id,user_id) VALUES(#{department_id},#{user_id})")
    int insertDepartmentUser(@Param("department_id") int department_id, @Param("user_id") int user_id);


}
